package com.study.talk.data.local;

import androidx.lifecycle.LiveData;
import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.Query;
import androidx.room.Update;

import com.study.talk.data.model.ChatCache;

import java.util.List;

@Dao
public interface ChatCacheDao {
    @Insert
    void insert(ChatCache cache);

    @Insert
    void insertAll(List<ChatCache> caches);

    @Delete
    void remove(ChatCache cache);

    @Delete
    void removeAll(List<ChatCache> caches);

    @Query("DELETE FROM chat_cache")
    void clear();

    @Update
    void update(ChatCache cache);

    @Query("SELECT * FROM chat_cache")
    LiveData<List<ChatCache>> query();

    @Query("SELECT * FROM chat_cache WHERE id=(:id)")
    ChatCache query(Integer id);

    @Query("SELECT COUNT(*) FROM chat_cache WHERE user_id=(:userId)")
    Boolean hasUser(Integer userId);

    @Query("SELECT COUNT(*) FROM chat_cache WHERE group_id=(:groupId)")
    Boolean hasGroup(Integer groupId);

    @Query("SELECT * FROM chat_cache WHERE user_id=(:userId)")
    ChatCache queryUser(Integer userId);

    @Query("SELECT * FROM chat_cache WHERE group_id=(:groupId)")
    ChatCache queryGroup(Integer groupId);
}
